package com.auxgroup.smarthome.business.controller;

import com.auxgroup.bridge.app.inner.vo.DeviceRepairVo;
import com.auxgroup.smarthome.business.service.inner.DeviceRepairInnerService;
import com.auxgroup.smarthome.utils.PageContent;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by root on 17-8-10.
 */
@Api(description = "一键报修", tags = "一键报修")
@RestController
public class ConsumerDeviceRepairController {

    @Autowired
    private DeviceRepairInnerService deviceRepairInnerService;

    @ApiOperation(value = "后台一键报修列表", notes = "一键报修--获取一键报修列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "报修ID/设备MAC/SN/用户名/手机号", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "integer", required = false),
            @ApiImplicitParam(name = "size", value = "分页大小", paramType = "query", dataType = "integer", required = false),
    })
    @RequestMapping(value = "/device_repair", method = RequestMethod.GET)
    public ApiResponse<Page<DeviceRepairVo>> getDeviceRepairList(@RequestParam(required = false) String keyword,
                                           @RequestParam(defaultValue = "0", required = false) Integer page,
                                           @RequestParam(defaultValue = "5", required = false) Integer size) {
        ApiResponse<PageContent<DeviceRepairVo>> apiResponse = deviceRepairInnerService.getDeviceRepairList(keyword, page, size);
        Page<DeviceRepairVo> pageContent = apiResponse.getData().convertPage();
        return new ApiResponse(apiResponse.getCode(), apiResponse.getMessage(), pageContent);
    }
}
